<?php
/**
 * Created by PhpStorm.
 * User: haobin
 * Date: 2016/11/14
 * Time: 16:06
 * description:广告点击分析
 */
require('../conn.php');
require('../functions.php');
require('admin.php');
$page = $_GET['page'];
if (is_numeric($page) == false) {
    $page = 1;
    $page_1 = 1;
    $min = 0;
    $page_2 = $page + 1;
} else {
    if ($page > 1) {
        $page_2 = $page + 1;
        $min = ($page - 1) * 20;
        $page_1 = $page - 1;
    } else {
        $page_1 = 1;
        $min = 0;
        $page_2 = 2;
    }
}
$max = 20;
$today = date("Y-m-d",time());
?>
<?php include('head.php') ?>
<div class="container-fluid">
    <div class="row-fluid">
        <?php
        include('left.php'); ?>
        <div class="span9">
            <h1 class="page-title">分享统计</h1>
            <h2><?=$today?></h2>
            <div class="well">
                <div id="myTabContent" class="tab-content">
                    <div class="tab-pane active in" id="home">
                        <div class="well">
                            <div class="pull-right">
                                <a class="btn btn-primary" href="?page=<?=$page_1?>">上一页</a>
                                <a class="btn btn-success" href="?page=<?=$page_2?>">下一页</a>
                            </div>
                            <table class="table">
                                <thead>
                                <tr>
                                    <th>#</th>
                                    <th>id</th>
                                    <th>姓名</th>
                                    <th>文章总量</th>
                                    <th>广告总量(上,中,下,其他)</th>
                                    <th>广告率</th>
                                    <th>安卓|(百分比)</th>
                                    <th>苹果|(百分比)</th>
                                </tr>
                                </thead>
                                <tbody>
                                <?php
                                $row = $mysql->query(" select count(id) as num,uid from sharedata WHERE `day`='{$today}' AND type != 2 GROUP BY uid ORDER BY num DESC limit {$min},{$max}");
                                $i = 0;
                                foreach ($row as $tx) {
                                    $i++;
                                    $id = $tx['uid'];
                                    $name = $mysql->query("select name from user where id = {$id}");
                                    $ad = $mysql->query("SELECT count(id) as num,uid from adpv where  `day`='{$today}' AND uid={$id}");
                                    $ad1 = $mysql->query("SELECT count(id) as num,uid from adpv where  `day`='{$today}' AND uid={$id} AND `location`=1");
                                    $ad2 = $mysql->query("SELECT count(id) as num,uid from adpv where  `day`='{$today}' AND uid={$id} AND `location`=2");
                                    $ad3 = $mysql->query("SELECT count(id) as num,uid from adpv where  `day`='{$today}' AND uid={$id} AND `location`=3");
                                    $ad4 = $mysql->query("SELECT count(id) as num,uid from adpv where  `day`='{$today}' AND uid={$id} AND `location`=0");
                                    $android = $mysql->query("SELECT count(id) as num from sharedata where  `day`='{$today}' AND uid={$id} AND type != 2 AND device='android'");
                                    $anpercent = number_format($android[0]['num']/$tx['num'],2);
                                    $apple = $mysql->query("SELECT count(id) as num from sharedata where  `day`='{$today}' AND uid={$id} AND type != 2 AND device='iphone'");
                                    $appercent = number_format($apple[0]['num']/$tx['num'],2);
                                    $adpercent = number_format($ad[0]['num']/$tx['num'],2);
                                    print <<<table
        <tr>
          <td><a href="./shareip.php?uid={$id}">{$i}</a></td>
		  <td><a href="./lastshare.php?uid={$id}">{$id}</a></td>
		  <td>{$name[0]['name']}</td>
		  <td>{$tx['num']}</td>
		  <td>{$ad[0]['num']} ({$ad1[0]['num']},{$ad2[0]['num']},{$ad3[0]['num']},{$ad4[0]['num']})</td>
		  <td>{$adpercent}</td>
		  <td>{$android[0]['num']} | ({$anpercent})</td>
		  <td>{$apple[0]['num']} | ({$appercent})</td>
        </tr>
table;
                                } ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <div class="tab-pane fade" id="profile">
                    </div>
                </div>

            </div>

        </div>
    </div>
</div>
<script src="lib/bootstrap/js/bootstrap.js"></script>
</body>
</html>

